/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package packageModel;

import java.io.Serializable;
import java.util.HashMap;

/**
 *
 * @author laurent
 */
public class Basket implements Serializable
{
    private boolean delivered;
    private boolean paid;
    private BricoWebUser user;
    private HashMap <String, ProductsLine> hashProductsLine;
 
    
    public Basket(BricoWebUser user)
    {
        this.delivered = false;
        this.paid = false;
        this.user = user;
        this.hashProductsLine = new HashMap <String, ProductsLine>();
    }
     public Basket()
    {
        this.delivered = false;
        this.paid = false;
        this.hashProductsLine = new HashMap <String, ProductsLine>();
    }
     
    public HashMap<String, ProductsLine> getHashProductsLine() { return this.hashProductsLine;}
    public boolean getDelivered() { return this.delivered; }
    public boolean getPaid() { return this.paid; }
    public BricoWebUser getUser() { return this.user; }
    
    public void setDelivered(boolean delivered) { this.delivered = delivered; }
    public void setPaid(boolean paid) { this.paid = paid; }
    public void setUser(BricoWebUser user) {this.user = user; }
    
    public void addProducts(Product product, int quantity)
    {
        if(hashProductsLine.containsKey(String.valueOf(product.getId())))
        {
            //si la promotion a changée entre deux ajouts, il faut rafraichir le produit dans la hashmap
            int nbProd = hashProductsLine.get(String.valueOf(product.getId())).getNbProducts()+quantity;
            hashProductsLine.remove(String.valueOf(product.getId()));
            ProductsLine prodLine = new ProductsLine(product, nbProd);
            hashProductsLine.put(String.valueOf(product.getId()), prodLine);
        }
        else
        {
            ProductsLine prodLine = new ProductsLine(product, quantity);
            hashProductsLine.put(String.valueOf(product.getId()), prodLine);
        }
           
    }
}
